home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
03 - Advanced Graphics
/
Example 7
/
background.c
next >
Wrap
Text File
|
1995-02-28
|
3KB
|
125 lines
//
// File: background.c
//
// This file contains routines that draw the background.
//
// 2/19/95 -- Created by Mick
//
// include files
#include "global.h"
#include "background.h"
#include "demo.h"
#include "main.h"
// defines for this file
// global function declarations
void startupBackground( void );
void shutdownBackground( void );
void restoreBackground( Rect *inRect );
// global data owned by this file
// local function declarations
// static data
static GWorldPtr sBackgroundWorld; // the GWorld of the background
static PixMapHandle sBackgroundPixels; // the pixmap of the background
// functions
//
// startupBackground -
//
// Allocate and load any data needed for the background.
//
void startupBackground( void )
{
PicHandle backgroundPict; // the background in pict form
CGrafPtr oldPort; // the current port
GDHandle oldGDevice; // the current gdevice
// load the pict
backgroundPict = GetPicture( kBackgroundPictResID );
// create the gworld
NewGWorld( &sBackgroundWorld, 8, &( ( *backgroundPict )->picFrame ),
gAppColorTable, ( GDHandle )kNil, keepLocal );
// get the pixmap
sBackgroundPixels = GetGWorldPixMap( sBackgroundWorld );
// lock the pixels
LockPixels( sBackgroundPixels );
// save the old port and device
GetGWorld( &oldPort, &oldGDevice );
// set the new gworld
SetGWorld( sBackgroundWorld, ( GDHandle )kNil );
// draw the picture
DrawPicture( backgroundPict, &( ( *backgroundPict )->picFrame ) );
// dump the picture
ReleaseResource( ( Handle )backgroundPict );
// restore the old port and device
SetGWorld( oldPort, oldGDevice );
// lock the pixels
UnlockPixels( sBackgroundPixels );
// dump the pict
ReleaseResource( ( Handle )backgroundPict );
}
//
// shutdownBackground -
//
// Free any memory used by the background.
//
void shutdownBackground( void )
{
// dump the gworld
DisposeGWorld( sBackgroundWorld );
}
//
// restoreBackground -
//
// Draw the background in the given rect.
//
void restoreBackground( Rect *inRect )
{
// lock the pixels
LockPixels( sBackgroundPixels );
// make sure that the fore and back colors are correct to prevent colorize mode
ForeColor( blackColor );
BackColor( whiteColor );
// Copy the screen's color table seed into the source pixmap.
// This will minimize CopyBits' setup time.
( *( ( *sBackgroundPixels )->pmTable ) )->ctSeed = ( *( ( *gOffscreenPixels )->pmTable ) )->ctSeed;
// copy the buffer to the screen
CopyBits( ( BitMap * )( *sBackgroundPixels ), ( BitMap * )( *gOffscreenPixels ),
inRect, inRect, srcCopy, ( RgnHandle )kNil );
// lock the pixels
UnlockPixels( sBackgroundPixels );
}